package com.winspread.active.extension

import android.app.Activity
import android.content.Intent
import android.content.res.Resources
import android.util.Log
import android.util.TypedValue
import android.widget.Toast
import com.winspread.mvvm.BuildConfig
import com.winspread.mvvm.MvvmApplication

/**
 * 这是扩展函数
 */

val Float.dp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        this,
        Resources.getSystem().displayMetrics
    )


var isLog = true

// 给方法变量添加默认值,使用方法时,可以不传值
fun String.i(TAG: String = ">>>>") {
    if (isLog)
        Log.i(TAG, this)
}



fun String.d(TAG: String? = ">>>>") {
    if (isLog)
        Log.d(TAG ?: ">>>>", this)
}

fun String.loge(TAG: String = "----->>>>>") {
    if (isLog)
        Log.e(TAG, this)
}

fun Boolean.toInt(): Int {
    return if (this) {
        0
    } else {
        -1
    }
}


fun Int.toBoolean(): Boolean {
    return this == 0
}


fun <T> Activity.startNewActivity(cls: Class<T>) {
    this.startActivity(Intent(this, cls))
}


fun String.toast(){
    Toast.makeText(MvvmApplication.context, this, Toast.LENGTH_SHORT).show()
}